package com.blog.backend.service.impl;

import com.blog.backend.mapper.ClassifyTagMapper;
import com.blog.backend.model.BlogPlate;
import com.blog.backend.req.TagReq;
import com.blog.backend.resp.ClassifyResp;
import com.blog.backend.resp.TagResp;
import com.blog.backend.service.ClassifyTagService;
import com.blog.backend.utils.PageUtils;
import com.blog.backend.utils.UuidUtils;
import com.blog.backend.vo.PageRequest;
import com.blog.backend.vo.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ClassifyTagServiceImpl implements ClassifyTagService {

    @Autowired
    private ClassifyTagMapper classifyTagMapper;
    @Override
    public List<TagResp> selectTagList(String classifyId) {
        log.info("分类id：{}",classifyId);
        List<TagResp> list=classifyTagMapper.selectTagList(classifyId);
        return list;
    }

    @Override
    public List<ClassifyResp> selectClassifyList(String type) {
        List<ClassifyResp> list= classifyTagMapper.selectClassifyList(type);
        return list;
    }

    @Override
    public Boolean insertTag(TagReq tagReq) {
        if (StringUtils.isNotBlank(tagReq.getTagId())){
            classifyTagMapper.updateTag(tagReq);
        }else {
            tagReq.setTagId(UuidUtils.getId());
            classifyTagMapper.insertTag(tagReq);
        }
        return true;
    }

    @Override
    public PageResult selectPageTags(PageRequest request) {
        log.info("卡签列表查询:{}",request);
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<TagResp> list = classifyTagMapper.selectList(request);
        PageInfo info=new PageInfo<TagResp>(list);
        PageRequest pageRequest = new PageRequest();
        PageResult pageResult = PageUtils.getPageResult(pageRequest, info);
        return pageResult;
    }
}
